package com.kancy.xml;

import com.kancy.xml.entity.*;
import com.kancy.xml.utils.XmlUtils;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import java.io.File;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;

public class Main {

    public static void main(String[] args) {

        List<Service> services = new ArrayList<Service>();
        Service s1 = new Service("com.kancy.xml.entity.Service1","s1");
        s1.setProductDate(new Date());
        Service s2 = new Service("com.kancy.xml.entity.Service2","s2");
        s2.getProperties().add(new Property("test","12345678"));

        Property p1 = new Property("name", "kancy");
        Property p2 = new Property("phone", "18079637331");

        Task task = new Task();
        task.getProperties().add(p1);
        task.getProperties().add(p2);

        task.getServices().add(s1);
        task.getServices().add(s2);

        XmlUtils.objectToxml(task,new File("./task.xml"));


        Task t = XmlUtils.xmlToObject(new File("./task.xml"), Task.class);

        System.out.println(t);

    }
}
